import { _decorator, Component } from 'cc';
import { KKP2D } from "@coldcloude/kakera";
import { GridForm } from '@coldcloude/kakera';
const { ccclass } = _decorator;

@ccclass('MapGrid')
export class MapGrid extends Component {
    refMap: MapGrid;
    grid: KKP2D;
    layer: number;
    calcGrid():KKP2D{
        if(!this.refMap){
            return this.grid;
        }
        else{
            let x = this.grid.x;
            let y = this.grid.y;
            let curr = this.refMap;
            while(curr){
                const g = curr.grid;
                x += g.x;
                y += g.y;
                curr = curr.refMap;
            }
            return {
                x: x,
                y: y,
            };
        }
    }
    calcPixel(gridForm:GridForm){
        const g = this.calcGrid();
        return gridForm.toPixel(g);
    }
}
